home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Tool Chest / Testing & Debugging / Virtual User tools / SPEC S&L v.1.0.1 / Libraries / LaunchQuit.Lib < prev    next >
Encoding:
Text File  |  1993-12-17  |  35.7 KB  |  975 lines  |  [TEXT/MPS ]

  1. #
  2. # ****************************************************************************
  3. #
  4. #    File Name:    LaunchQuit.Lib
  5. #
  6. #    Contains:    Launching and Quiting tasks
  7. #
  8. #    Written by:    Kevin Avoy, Ken Landreth, Michael Leong, Gil Spencer et al
  9. #
  10. #    Copyright:    © 1993 by Apple Computer, Inc., all rights reserved.
  11. #
  12. # ****************************************************************************
  13. #            C h a n g e        H i s t o r y (most recent first):
  14. # ****************************************************************************
  15. #
  16. #        Vers      Date        Author        Description
  17. #        ----    --------    ------    ---------------------------------------------
  18. #    <1.0.23>    12/16/93    KTA        Fixed but in the new exception handling mechanism.
  19. #    <1.0.22>    12/13/93    KTA        Removed calls to ExpectionHandler directly, now call TCSEnd()
  20. #                                    with a fatal Flag if necessary.
  21. #    <1.0.21>     12/2/93    KTA        Added gLaunchTwitchHook1,2,3,4. Also added support for 'PowerPC'
  22. #                                    and '68k' in gLaunchReqs.
  23. #    <1.0.20>    11/19/93    NAGA    modify TCS format
  24. #    <1.0.19>     9/22/93    KTA        Problem matching substrings as well are special characters.
  25. #    <1.0.18>     9/22/93    KTA        Call the gExceptionHandler task reference instead of calling the
  26. #                                    task directly.
  27. #    <1.0.17>     9/20/93    KTA        LaunchByTypeSelect() Bug Fix - No mem string was returned
  28. #                                    expected -3 caused an unbalanced TCS stack.
  29. #    <1.0.16>     9/13/93    KTA        LaunchTwitch() - intl - regular expressions errors.
  30. #    <1.0.15>     9/10/93    KTA        Removed all slang phrases from output.
  31. #    <1.0.14>      9/9/93    KTA        Twitcher() - Removed the phrase - 'Sorry Charlie' from the
  32. #                                    output line.
  33. #    <1.0.13>      9/7/93    KTA        BugFix LaunchTwitch() -  Problem with ill-formed regular
  34. #                                    expressions.
  35. #    <1.0.12>     8/25/93    KTA        Added support for parity checking the TCS stack.
  36. #    <1.0.11>     8/20/93    KTA        LaunchTwitch() - removed duplicate output lines.
  37. #    <1.0.10>     8/20/93    KTA        LaunchTwitch() -  fixed problem where we were looking in
  38. #                                    Applemenu before processlist.
  39. #     <1.0.9>     7/30/93    KTA        LaunchTwitch(), LaunchByAppleMenu(), LaunchAssist() - updates so
  40. #                                    when app doesn't have enough memory to launch it will be handled
  41. #                                    as expected failure.
  42. #     <1.0.8>     7/15/93    KTA        Updated references to tasks in Gestalt.Lib whose names had
  43. #                                    changed.
  44. #     <1.0.7>     7/14/93    KTA        Updated for international support
  45. #     <1.0.6>      7/6/93    KTA        Merge Michael suggested changes for SPEC
  46. #        <1+>     5/21/93    NAGA        Adding header and porting old files to follow new standards
  47. #
  48. # ****************************************************************************
  49. #
  50.  
  51. ########################################################################
  52. #                            External libraries 
  53. #=======================================================================
  54. Libraries "TCS.Lib" , "Output.Lib", "String.Lib", "Gestalt.Lib", "StandardFile.Lib", "OnTarget.Lib", "TargetCheck.Lib","UserInterface.Lib";
  55.  
  56.  
  57. #########################################################################
  58. #                             Twitcher(appName)    
  59. #========================================================================
  60. # Author:         DM
  61. # Description:    This Task is intended to select apps from the Process List
  62. #                menu in System 7.0.  Use LaunchTwitch to handle launching 
  63. #                or twitching applications.
  64. #                This routine selects apps from the Process List.
  65. # Parameters:        appName - app to twitch to.
  66. # Returns:            0 if twitching to appName fails
  67. #                    TheCurrentApp - if twitching was successful
  68. # Examples:            Twitcher("MacWrite 5.0");
  69. # Assumptions:        None
  70. #========================================================================
  71. # History:
  72. # KTA    7/14/93 Changed check for process list from Hide others to Finder
  73. # KTA    8/24/93    TCS stack parity check
  74. # KTA    9/9/93    Removed the phrase - 'Sorry Charlie' from the output line
  75. #########################################################################
  76. TASK Twitcher(appName := "") 
  77. begin
  78.     returnval:= 0;
  79.     if (Global gIsSys7)
  80.     begin                # Was 'Hide Others' changed for intl
  81.         match[menuItem t:"Finder" m:[menu o:?menuOrd] ]!;
  82.         match[application t:?CurrApp];
  83.         tempAppName := "'"+ AppName + "'";
  84.         ApplicationMI := match[menuItem t:/≈{tempAppName}≈/ m:[menu o:menuOrd] ]!; 
  85.         if not ( ApplicationMI )    # for special chars in appname
  86.             ApplicationMI := match[menuItem t:appName m:[menu o:menuOrd] ]!;
  87.         if ( ApplicationMI )
  88.         begin
  89.             if not(ApplicationMI.t ~= /Hide≈/!)
  90.             begin
  91.                 TCSStart({ 4, global kTCSetLaunch },"Twitch from one application to another via process list");
  92.                 select ApplicationMI;
  93.                 AppName := ApplicationMI.t;
  94.                 LogStr("Twitched to {AppName} by way of the process list",3);
  95.                 wait(2);
  96.                 TheCurrentApp := MatchApplication(1);
  97.                 if(isSubString(appName,TheCurrentApp))        #Check to see if App is frontmost
  98.                     returnval:= TheCurrentApp;
  99.                 TCSEnd({ 4, global kTCSetLaunch }, returnval,,,"From '{CurrApp}' to '{AppName}'");
  100.             end; # if not(ApplicationMI.t ~= /Hide≈/!)
  101.         end; # if ( ApplicationMI )
  102.         else # not if ( ApplicationMI )
  103.             LogStr("Couldn't select '{appName}' from the process list");
  104.     end; # (Global gIsSys7)
  105.     return(returnval);
  106. end; # Twitcher()
  107.  
  108.  
  109. #########################################################################
  110. #                MiniLaunch(appTitle, LaunchApp, SetDir)
  111. #========================================================================
  112. # Author:        NJV - DMM
  113. # Description:    This routine will launch an application on the target
  114. #                machine(s).  The miniLauncher tool should be the running
  115. #                application on the target machine(s).  This routine will
  116. #                type the input parameter appTitle to the target machine
  117. #                and then type the return key (which is how an application
  118. #                is launched using miniLauncher.)  The application to be
  119. #                launched must reside in a folder beneath the miniLauncher
  120. #                tool in the directory hierarchy. For more information on
  121. #                the miniLauncher tool, see the read-me that accompanies
  122. #                the tool.  
  123. #                MiniLauncher can also open or print documents.  See the
  124. #                LaunchApp parameter description below for more details.
  125. #
  126. # Parameters:    appTitle -    title of the application or document to be launched.
  127. #                            The title does not have to be complete.  The MiniLauncher
  128. #                            tool will launch the first application it finds
  129. #                            starting with the string appTitle.  If LaunchApp
  130. #                            parameter is not 1, then appTitle will hold the
  131. #                            document name to be opened or printed.
  132. #                LaunchApp - 1 to launch application
  133. #                            0 to launch application via a document
  134. #                            -1 to print a document (launch app and print)
  135. #                SetDir    -    1 to set the default directory to that of the
  136. #                                application
  137. #                            0 to bypass setting of default directory (will
  138. #                                end up being MiniLauncher's directory).
  139. #
  140. # Returns:        1 - Launched OK
  141. #                0 - Couldn't launch application (usually due to lack of 
  142. #                        enough memory on the target machine).
  143. #
  144. # Examples:        MiniLaunch('Word');
  145. #========================================================================
  146. # History:
  147. #
  148. #########################################################################
  149. TASK MiniLaunch(appTitle, LaunchApp := 1,SetDir := 1) begin
  150.     returnVal := 0;
  151.     if not(match[window t:"MiniLauncher" o:1]!)
  152.     begin
  153.         MiniLauncher := match[menuitem t:/MiniLauncher≈/ m:[menu t:'']];        # is it in the Apple menu
  154.         if (MiniLauncher)            # if so select it
  155.         begin
  156.             select MiniLauncher;
  157.             LogStr("Selected Minilauncher");
  158.             returnVal := 1;
  159.         end;
  160.         else
  161.             LogStr("MiniLauncher is not currently running");
  162.     end;
  163.     else
  164.         returnVal := 1;            # Minilauncher is the front window
  165.     
  166.     if(returnVal)
  167.     begin
  168.         Println "    -- MiniLauncher --";        # So log reflects what is going down
  169.         # if LaunchApp is 0 check for newest version of MiniLauncher
  170.         foo := match [button t:'Options']!;
  171.         if (LaunchApp <> 1) 
  172.         begin
  173.             if (not foo) begin
  174.                 if (LaunchApp = -1)  # user trying to print document
  175.                     LogStr("Wrong version of MiniLauncher for printing documents - use v1.3b or newer.");
  176.                 else
  177.                     LogStr("Wrong version of MiniLauncher for launching documents - use v1.3b or newer.");
  178.             end;
  179.             else
  180.                 SelectButton('Options');
  181.             if (LaunchApp = -1)    # user wants to print document
  182.                 SelectRadioButton('Print Document');
  183.             else
  184.                 SelectRadioButton('Open Document');
  185.             
  186.             SelectButton("OK");
  187.         end;
  188.         else if (foo) 
  189.         begin
  190.             SelectButton('Options');
  191.             SelectRadioButton('Launch Application');
  192.             if (SetDir)
  193.                 SelectRadioButton("Application∂'s Directory");
  194.             else
  195.                 SelectRadioButton("MiniLauncher∂'s Directory");
  196.             SelectButton('OK');
  197.         end;
  198.  
  199.         TypeStr(appTitle);
  200.         SpecialKey(returnKey , "Return Key");
  201.         if(DialogCheck("An error has occurred", 'OK'))
  202.         begin
  203.             returnVal := 0;
  204.             DialogCheck('','OK');        # Any additional dialogs
  205.         end;
  206.         if(returnVal)    
  207.             MatchApplication(0);
  208.     end;
  209.     return(returnVal);
  210. end;  # MiniLaunch()
  211.  
  212. #########################################################################
  213. #                         Quit(OverWrite, DocName)
  214. #=======================================================================
  215. # Author:          KTA
  216. # Description:    Will turn off the Application Verification scheme, Select
  217. #                the Quit menu item, check whether or not to save changes,
  218. #                then reset the App verification scheme to its previous state.
  219. # Parameters:    OverWrite    1    - Save changes.
  220. #                            0    - Don't save changes.
  221. #                DocName        -    The string that will be used to save the document
  222. #                HowQuit        1    - Select "Quit" from File Menu
  223. #                            2    - Type Cmd-Q to quit
  224. #            CloseScrapbook    1    - close the scrapbook after quitting
  225. #                            0    - don't close the scrapbook after quitting
  226. #        CloseFinderWindows    1    - close finder windows after quitting
  227. #                            0    - don't close finder windows after quitting    
  228. # Returns:                    -2     - All quitting bypassed (gForceQuit enabled)
  229. #                            -1    - Closed all windows of current app (gBackgroundQuit enabled)
  230. #                             0    - Unable to quit current app
  231. #                             1    - successfully quit current app
  232. #=======================================================================
  233. # History:
  234. # KTA    7/7/93    Made the title of the scrapbook a resource, changed references to it.
  235. # KTA    8/24/93    TCS stack parity check
  236. # KTA    9/9/93    Removed all slang from output lines.
  237. #########################################################################
  238. TASK Quit(OverWrite :=1,DocName:="",HowQuit :=1, CloseScrapbook:=1, CloseFinderWindows:=1)
  239. begin
  240.     returnval := 0;
  241.     global gAppverify, gstartTime, gBackgroundQuit, gIsSys7, gFillMemory, gFillMemApp, gForceQuit,gScrapTitle;
  242.     
  243.     if not gForceQuit
  244.     begin
  245.         TheCurrentApp := MatchApplication();
  246.         
  247.         if (TheCurrentApp <> 'Finder')    # make sure you're not trying to quit the finder
  248.         begin
  249.             
  250.             if ((gBackgroundQuit) and (gIsSys7))        # if Background quit enabled and 7.x
  251.             begin
  252.                 logstr('global gBackgroundQuit is enabled so closing all windows instead of actively quitting');
  253.                 CloseAllWindows();                    # close the open document window
  254.                 returnval := -1;
  255.             end;
  256.             
  257.             else if ((gBackgroundQuit) and not (gIsSys7))    # BG quit enabled but not 7.x
  258.                 logstr('!@#$% Not System 7.x.  Background quit not available.  Will actively quit application.');
  259.             
  260.             if (not (gBackgroundQuit) or not (gIsSys7))
  261.             begin
  262.             
  263.                 temp := gAppverify;
  264.                 gAppVerify := 0;
  265.             
  266.                 if (HowQuit = 1)
  267.                 begin
  268.                     TCSNum := 1;
  269.                     TCSStart({ TCSNum, global kTCSetQuit },"Select the 'Quit' menuitem");
  270.                     SelectMenuItem('Quit','File');     #Quit MenuItem
  271.                 end; # if (HowQuit = 1)
  272.                 else if (HowQuit = 2)
  273.                 begin
  274.                     TCSNum := 2;
  275.                     TCSStart({ TCSNum, global kTCSetQuit },"Type command - Q");
  276.                     keyEq('q');                        #Key Equiv 'q'
  277.                 end; # if (HowQuit = 2)
  278.                 wait(2);
  279.             
  280.                 while(checkYesNo(overwrite))
  281.                 begin
  282.                     If(overWrite)
  283.                         if (match[button t:"Save"]!) or (match[button t:"OK"]!) or (match[button t:"Yes"]!)        # If SF dialog comes up     #
  284.                             SaveAs(DocName,true);
  285.                     wait(3);
  286.                 end; # while(checkYesNo(overwrite))
  287.                 
  288.                 # check if TheCurrentApp is no longer in process list
  289.                 Twitcher (TheCurrentApp);
  290.                 if (MatchApplication(0) = TheCurrentApp)
  291.                     logstr("!@#$% Unable to quit '{TheCurrentApp}'!");
  292.                 else
  293.                 begin
  294.                     logstr("Quit '{TheCurrentApp}' successfully.");
  295.                     returnval := 1;
  296.                 end;
  297.                 TCSEnd({ TCSNum, global kTCSetQuit }, returnval);
  298.             end; # if (not (gBackgroundQuit) or not (gIsSys7))
  299.             
  300.         end; # if (TheCurrentApp <> 'Finder')
  301.         
  302.         else # if (TheCurrentApp = 'Finder')
  303.                 logstr("It is not possible to quit the Finder!!! ");
  304.                 
  305.         # if scrapbook is open, close it
  306.         if (CloseScrapbook)
  307.         begin
  308.             if (typeOf(temp) = 'undefined')
  309.             begin
  310.                 temp:= gAppverify;
  311.                 gAppverify:=0;
  312.             end;
  313.             Twitcher (gScrapTitle);
  314.             if (MatchApplication(0) = gScrapTitle)
  315.             begin
  316.                 closeWindow(,,gScrapTitle);
  317.                 wait(2);
  318.             end;
  319.         end; # if CloseScrapbook
  320.         
  321.         # twitch to finder, close all open windows
  322.         Twitcher ("Finder");
  323.         if (MatchApplication(0) = "Finder")
  324.         begin
  325.             if CloseFinderWindows
  326.                 KeyEq('w',2);
  327.         end;
  328.         MatchApplication();
  329.         println;
  330.     end; # if not gForceQuit
  331.     
  332.     else # if gForceQuit
  333.         logstr("Global gForceQuit is enabled, so quitting '{global gapptitle}' is bypassed.");
  334.         returnval:= -2;
  335.         
  336.     # if gFillMemory, quit gFillMemApp
  337.     if (gFillMemory)
  338.     begin
  339.         if (typeOf(temp) = 'undefined')
  340.         begin
  341.             temp:= gAppverify;
  342.             gAppverify:=0;
  343.         end;
  344.         Twitcher (gFillMemApp);
  345.         if (MatchApplication(0) = gFillMemApp)
  346.         begin
  347.             Logstr("Trying to quit the gFillMemApp '{gFillMemApp}'");
  348.             TCSNum := 1;
  349.             TCSStart({ TCSNum, global kTCSetQuit },"Selected the 'Quit' menuitem");
  350.             SelectMenuItem("Quit","File");     #Quit MenuItem
  351.             checkYesNo(false);
  352.             wait(2);
  353.             Twitcher (gFillMemApp);
  354.             if (MatchApplication(0) = gFillMemApp)
  355.             begin
  356.                 logstr("!@#$% Unable to quit '{gFillMemApp}'");
  357.                 TCSEnd({ TCSNum, global kTCSetQuit }, 0);
  358.             end;
  359.             else
  360.             begin
  361.                 logstr("Quit '{gFillMemApp}' successfully.");
  362.                 TCSEnd({ TCSNum, global kTCSetQuit }, 1);
  363.             end;
  364.         end; # if (MatchApplication(0) = gFillMemApp)
  365.     end; # if (gFillMemory)
  366.             
  367.     if not (typeOf(temp) = 'undefined')
  368.         gAppVerify := temp;
  369.     return(returnval);
  370.     
  371. end; # Quit()
  372.  
  373. #########################################################################
  374. #            QuitBackgroundApps()
  375. #========================================================================
  376. # Author:            ML
  377. # Description:        Checks for Background Quit Dialog, then
  378. #                    chooses "quit apps" if BackgroundQuit is ON or 
  379. #                    "Cancel" if it's OFF.
  380. # Parameters:        None
  381. # Returns:            -2    Couldn't dismiss BG Quit dialog
  382. #                    -1    BG Quit dialog present, "Cancel" button selected
  383. #                     0    BG Quit dialog not present
  384. #                     1    BG Quit dialog present, "Quit apps" button selected
  385. # Assumptions:        7.x
  386. #========================================================================
  387. # History:
  388. # KTA    8/24/93        TCS stack parity check
  389. #########################################################################
  390. TASK QuitBackgroundApps() 
  391. begin
  392.     global gBackgroundQuit;
  393.     returnval :=0;
  394.     # dialogcheck doesn't work here, check for background quit buttons
  395.     if (match [button t:/Quit Application≈/]!)
  396.     begin
  397.         match [window t:'' o:1 k:{ [staticText t:?mytext] }]!;    # get the static text
  398.         logstr("Found dialog: {mytext}");                        # log out the static text
  399.         if (gBackgroundQuit)            # if background quit enabled
  400.         begin
  401.             TCSNum := 3;
  402.             TCSStart({ TCSNum, global kTCSetQuit },"BG Quit - Select 'Quit Application(s)'");
  403.             selectbutton (/Quit Application≈/);    # select the "Quit Application(s)" button
  404.             returnval := 1;
  405.             wait(15);    # long wait in case of multiple background quits
  406.         end; # if (gBackgroundQuit)
  407.         else    # not gBackgroundQuit
  408.         begin
  409.             TCSNum := 4;
  410.             TCSStart({ TCSNum, global kTCSetQuit },"BG Quit - Select 'Cancel'");
  411.             selectbutton ('Cancel');    # else don't background quit
  412.             returnval := -1;
  413.         end;    # not gBackgroundQuit
  414.         if not match [button t:/Quit Application≈/]    # did BG Quit dialog get dismissed?
  415.             TCSEnd({ TCSNum, global kTCSetQuit }, 1);    #    if so, pass TCS
  416.         else begin    #    if not, reset returnval, fail TCS
  417.             returnval := -2;
  418.             TCSEnd({ TCSNum, global kTCSetQuit }, 0);
  419.         end;
  420.     end; # if (match [button t:/Quit Application≈/]!)
  421.     return(returnval);
  422. end;
  423.  
  424. #########################################################################
  425. #            TwitchQuit()
  426. #========================================================================
  427. # Author:            ML
  428. # Description:        Selects the fifth item (first app or da) in the process list, or sixth        
  429. #                    if the fifth is "Finder", and quits it.
  430. # Parameters:        None
  431. # Returns:            0 - Could not quit an app or da
  432. #                    1 - quit app or da ok
  433. # Assumptions:        7.0x -  There is a process list
  434. #========================================================================
  435. # History:
  436. #
  437. ########################################################################
  438. TASK TwitchQuit() 
  439. begin
  440.  
  441.     global gIsSys7, gForceQuit, gBackgroundQuit, gAppverify, gFillMemory;
  442.     returnval:=0;
  443.     
  444.     if ((gIsSys7) and (gForceQuit))
  445.     begin
  446.         Twitcher('Finder');                                        # make sure we're starting from the finder
  447.         logstr('Attempting to twitch to and quit the first open app or DA');
  448.         match[menuItem t:"Hide Others" m:[menu o:?menuOrd] ]!;    # get ord of process list
  449.         match[menuItem o:5 t:?AppToQuit m:[menu o:menuOrd] ]!;    # get title of app to quit
  450.         if (AppToQuit = 'Finder')                                # if fifth menuitem is finder
  451.             match[menuItem o:6 t:?AppToQuit m:[menu o:menuOrd] ]!;    # get title of sixth
  452.                 
  453.         if (AppToQuit <> 'Finder')                                # if we've identified an app to quit
  454.         begin
  455.             temp := gAppverify;
  456.             gAppverify := 0;
  457.             if (AppToQuit = Twitcher(AppToQuit))    # twitch to it                
  458.             begin
  459.                 temp1 := gBackgroundQuit;                        # set globals
  460.                 gBackgroundQuit := 0;                            # for active quit
  461.                 temp2 := gForceQuit;                                
  462.                 gForceQuit := 0;
  463.                 temp3 := gFillMemory;
  464.                 gFillMemory := 0;
  465.                 returnval := Quit(,,,0,0);            #    call Quit Task
  466.                 gBackgroundQuit := temp1;
  467.                 gForceQuit := temp2;
  468.                 gFillMemory := temp3;
  469.             end; # (AppToQuit = (Twitcher(AppToQuit))
  470.             
  471.             else    # couldn't twitch to app
  472.                 logstr("!@#$% Could not twitch to {AppToQuit}.");
  473.                 
  474.             gAppverify := temp;
  475.         end; # if (AppToQuit <> 'Finder')
  476.         else # AppToQuit still equals finder - nothing to quit
  477.             logstr("Unable to identify any applications or DA's to quit.");
  478.             
  479.     end; # if ((gIsSys7) and (gForceQuit))
  480.     else
  481.         returnval:=-1;
  482.         
  483.     return(returnval);
  484. end; # TwitchQuit()
  485.  
  486. #########################################################################
  487. #            LaunchAssist()
  488. #========================================================================
  489. # Author:            ML
  490. # Description:        Assist launch process by background quitting, checking
  491. #                    for "not enough memory" dialogs, and twitch and quitting.
  492. # Parameters:        None
  493. # Returns:            -3 - unsuccessful- not enough memory
  494. #                    -2 - unsuccessful - background quit cancelled
  495. #                    -1 - unsuccessful - twitchquit failed
  496. #                    0 -    unsuccessful - alias not found
  497. #                    1 - successful launch
  498. #                    2 - successful twitchquit
  499. # Assumptions:        7.0x -  There is a process list
  500. #========================================================================
  501. # History:
  502. #    ML    7/1/93        if BG quit cancelled, if gForceQuit is true, then do TwitchQuit.
  503. #
  504. ########################################################################
  505. TASK LaunchAssist() 
  506. begin
  507.     returnval:=0;
  508.     if not DialogCheck(/could not be found≈(≈∂n≈)*/,'OK')
  509.     begin
  510.         myBGQuit := QuitBackgroundApps();    # check for BG quit dialog
  511.         if  (myBGQuit = -1)                    # if BG Quit Dialog is cancelled
  512.         begin
  513.             returnval:=-2;                    # set returnval to indicate this
  514.             if not global gForceQuit        # if gForceQuit is false
  515.                 return(returnval);            # return returnval, end task
  516.         end;
  517.         # if BG quit cancelled and gForceQuit true, or not enough memory dialog
  518.         NoMemError := DialogCheck(/memory≈(≈∂n≈)*/,'OK');
  519.         if (returnval= -2 or NoMemError)    
  520.         begin
  521.             if (TwitchQuit() = 1)        # try to twitch and quit
  522.                 returnval:= 2;    # successful twitchquit
  523.             else if (TwitchQuit() = -1)
  524.                 returnval:= NoMemError ;    # No memory
  525.             else
  526.                 returnval:= -1;    # twitchquit failed
  527.         end; # 
  528.         else # no cancelled BG quits, no memory dialogs
  529.             returnval:=1;        # successful launch
  530.     end; # if not DialogCheck(/could not be found≈(≈∂n≈)*/,'OK')
  531.     return(returnval);
  532. end;
  533.  
  534. #########################################################################
  535. #            LaunchByAppleMenu()
  536. #========================================================================
  537. # Author:            ML
  538. # Description:        Launch via the Apple Menu
  539. # Parameters:        ItemName - name of app or DA to launch
  540. # Returns:            -3 - unsuccessful- not enough memory
  541. #                    -2 - unsuccessful - background quit cancelled
  542. #                    -1 - unsuccessful - twitchquit failed
  543. #                    0 -    unsuccessful - alias not found
  544. #                    1 - successful launch
  545. # Assumptions:        7.0x -  There is a process list
  546. #                    ItemName is in apple menu
  547. #========================================================================
  548. # History:
  549. # KTA    8/24/93        TCS stack parity check
  550. #########################################################################
  551. TASK LaunchByAppleMenu(ItemName) 
  552. begin
  553.     TCSStart({ 1, global kTCSetLaunch },"Selected an item in Apple Menu");
  554.     returnval:= 2; # initialize value for loop
  555.     While returnval = 2 # if first pass or twitchquit successful
  556.     begin
  557.         Selectmenuitem("{ItemName}", "");    # Select Apple MenuItem
  558.         wait(2);
  559.         returnval:= LaunchAssist() ;        # assist launch
  560.     end; # While returnval = 2
  561.  
  562.     if (returnval = 1)
  563.         TCSEnd({ 1, global kTCSetLaunch },1,,,"{ItemName}");
  564.     else if (TypeOf(returnval) = 'string')    # out of memory
  565.     begin
  566.         TCSEnd({ 1, global kTCSetLaunch }, -1, returnval);
  567.         returnVal := -3;
  568.     end;
  569.     else if (returnval = -2)
  570.         TCSEnd({ 1, global kTCSetLaunch }, 0, 'Background quit cancelled');
  571.     else if (returnval = -1)
  572.         TCSEnd({ 1, global kTCSetLaunch }, 0, 'TwitchQuit failed');
  573.     else if (returnval = 0)
  574.         TCSEnd({ 1, global kTCSetLaunch },-1, 'alias not found');
  575.     return (returnval);
  576. end;
  577.  
  578. #########################################################################
  579. #            LaunchByTypeSelect()
  580. #========================================================================
  581. # Author:            ML
  582. # Description:        Launch via type select
  583. # Parameters:        AppName - name of app or DA to launch
  584. #                    AliasDir - name of alias directory
  585. # Returns:            -3 - unsuccessful- not enough memory
  586. #                    -2 - unsuccessful - background quit cancelled
  587. #                    -1 - unsuccessful - twitchquit failed
  588. #                    0 -    unsuccessful - other
  589. #                    1 - successful launch
  590. # Assumptions:        7.0x -  There is a process list
  591. #========================================================================
  592. # History:
  593. # KTA    7/7/93    Changed SelectMenuItem('Open','File'); to KeyEq('o'); for intl
  594. # KTA    8/24/93    TCS stack parity check
  595. # KTA    9/20/93    Bug Fix - No mem string was returned expected -3 caused
  596. #                an unbalanced TCS stack
  597. #########################################################################
  598. TASK LaunchByTypeSelect(AppName, AliasDir := "") 
  599. begin
  600.     returnval:= 0;
  601.     if AliasDir                                    # if alias directory parameter passed
  602.     begin
  603.         if (match [menuItem t:AliasDir m:[menu t:""]])    # if AliasDir in the apple menu
  604.         begin
  605.             if (LaunchByAppleMenu(AliasDir) = 1) # if successful opening AliasDir
  606.             begin
  607.                 if (FindWindow(/≈{AliasDir}≈/))             # Is the right folder open
  608.                 begin
  609.                     TCSStart({ 2, global kTCSetLaunch },"Launch via Type Select");
  610.                     typeStr("{AppName}");        # Type the appName
  611.                     returnval:= 2;                 # initialize value for loop
  612.                     While returnval = 2         # if first pass or twitchquit successful
  613.                     begin
  614.                         KeyEq('o');                            # Open Intl
  615.                         wait(2);
  616.                         returnval:= LaunchAssist() ;        # assist launch
  617.                         if(TypeOf(returnval = 'string'))
  618.                         begin
  619.                             if(isSubString(/memory≈(≈∂n≈)*/, returnVal))
  620.                                 returnVal := -3;
  621.                         end;
  622.                     end; # While returnval = 2
  623.                     
  624.                     tempAppName := "'"+ AppName + "'";            # This is handle a problem that special characters can cause
  625.                     if (match[application t:/≈{tempAppName}≈/])
  626.                         TCSReturnVal := 1;
  627.                     else
  628.                         TCSReturnVal := 0;
  629.                         
  630.                     if (returnval = 1)
  631.                         TCSEnd({ 2, global kTCSetLaunch },TCSReturnVal,,,"{AppName}");
  632.                     else if (returnval = -3)
  633.                         TCSEnd({ 2, global kTCSetLaunch },-1, 'not enough memory');
  634.                     else if (returnval = -2)
  635.                         TCSEnd({ 2, global kTCSetLaunch },0, 'Background quit cancelled');
  636.                     else if (returnval = -1)
  637.                         TCSEnd({ 2, global kTCSetLaunch },0, 'TwitchQuit failed');
  638.                     else if (returnval = 0)
  639.                         TCSEnd({ 2, global kTCSetLaunch },-1, 'alias not found');
  640.                 end; # if (FindWindow(/≈{AliasDir}≈/))
  641.                 else
  642.                     logstr("The alias directory '{AliasDir}' wasn't opened");
  643.             end; # if successful opening AliasDir
  644.             else
  645.                 logstr("Unable to launch the '{AliasDir}' Apple menu item");
  646.         end; # if AliasDir in the apple menu
  647.         else
  648.             logstr("The alias directory '{AliasDir}' is not an apple menu item");
  649.     end; # if alias directory parameter passed
  650.     else
  651.         logstr("No alias directory defined");
  652.     return (returnval);
  653. end;
  654.  
  655. #########################################################################
  656. #            LaunchFillMemApp()
  657. #========================================================================
  658. # Author:            ML
  659. # Description:        Launch global gfillMemApp
  660. # Parameters:        None
  661. # Returns:            none
  662. # Assumptions:        7.0x -  There is a process list
  663. #                    Alias or original of gFillMemApp is in apple menu
  664. #                    or in alias directory.  Memory allocation of gFillMemApp
  665. #                    has been set high enough to fill up remaining memory.
  666. #========================================================================
  667. # History:
  668. #    ML    6/30/93        Set SuiteBailOut parameter in call to LaunchTwitch() to 0    
  669. ########################################################################
  670. TASK LaunchFillMemApp() 
  671. begin
  672.     # set globals so no recursive quitting/launching
  673.     tempgBackgroundQuit:= global gBackgroundQuit;
  674.     gBackgroundQuit:= 0;
  675.     tempgForceQuit:= global gForceQuit;
  676.     gForceQuit:= 0;
  677.     tempgFillMemory:= global gFillMemory;
  678.     gFillMemory:= 0;
  679.     
  680.     # launch gFillMemApp
  681.     LaunchTwitch(global gFillMemApp, global gAliasDirectory,,0);
  682.     
  683.     # reset globals
  684.     gBackgroundQuit:= tempgBackgroundQuit;
  685.     gForceQuit:= tempgForceQuit;
  686.     gFillMemory:= tempgFillMemory;
  687. end;
  688.  
  689.  
  690. #########################################################################
  691. #            LaunchTwitch(AppName, AliasDir, LaunchApp, SuiteBailOut)
  692. #========================================================================
  693. # Author:            KTA
  694. # Description:        This routine determines whether the Operating system is 
  695. #                    6.0x or 7.0x and launches the application accordingly.  
  696. #                    6.0x -  Will check the Apple menu to see if the App is 
  697. #                    currently running and select it if it is. If it is not running
  698. #                    it will select Mini from the Apple menu and call MiniLaunch(AppName);
  699. #                    7.0x -  Will check the ProcessList to see if the App is 
  700. #                    currently running and select it if it is.  if it is not it will
  701. #                    Select the Apple from the Apple Menu, or the <AliasDir> and then type
  702. #                    the <AppName> and select the Open menuItem.
  703. # Parameters:        AppName - Application to be launched/Twitched
  704. #                    AliasDir -  Folder in the Apple menu that contains <AppName>.
  705. #                    LaunchApp - 0    Select from Process list - Do not launch the App.
  706. #                                1    Select from Process list or launch the App if 
  707. #                                    necessary.
  708. #                    SuiteBailOut -    1    Call ExceptionHandler(-70) to bail out of suite if
  709. #                                        LaunchTwitch fails
  710. #                                    0    Don't call ExceptionHandler(-70) to bail out of suite if
  711. #                                        LaunchTwitch fails
  712. # Returns:            0 - App did not launch
  713. #                    AppName - Name of app that launched
  714. # Examples:            LaunchTwitch('MacWrite', "#CoreAliases");
  715. #                    LaunchTwitch('MacWrite Doc',"#CoreAliases",0);
  716. # Assumptions:        7.0x -  That the Application (or Alias) is resident in the 
  717. #                    Apple Menu or the <AliasDir> which contains <AppName> is.
  718. #========================================================================
  719. # History:
  720. # ML    7/1/93        Set default AliasDir to global gAliasDirectory
  721. #                    Check for modal dialog before launching gFillMemApp
  722. #                    Reset globals, if necessary, after all launching done
  723. # KTA    8/20/93        Bug Fix : we were looking in Applemenu before seeing 
  724. #                    if app was running.
  725. # KTA    8/24/93        TCS stack parity check
  726. # KTA    9/7/93        problem with ill-formed regular expressions
  727. # KTA    9/22/93        Problem matching substrings as well are special characters
  728. # KTA    12/01/93    gPatchLaunchTwich is now a global hook, made task more readable
  729. # KTA    12/01/93    Added gLaunchTwitchHook1, gLaunchTwitchHook2, gLaunchTwitchHook3, 
  730. #                    and gLaunchTwitchHook4
  731. # KTA    12/13/93    Preflight now fails TCS instead of calling ExceptionHandler directly 
  732. #########################################################################
  733. TASK LaunchTwitch(AppName, AliasDir:= global gAliasDirectory, LaunchApp := 1, SuiteBailOut:=1) 
  734. begin    
  735.     FailStr := '';                # Init misc variables
  736.     returnVal := 0;
  737.     
  738.     # Turn off app verification scheme temporarily
  739.     tempAppVerify := global gAppVerify;            
  740.     gAppVerify := 0;
  741.     
  742.     TCSStart({ 3, global kTCSetLaunch },"Launch or twitch to an application");
  743.     
  744.     if (global gLaunchTwitchHook1)        # Hook prior to preflight 
  745.         Call (gLaunchTwitchHook1);
  746.     
  747.     if (global gPreFlight)                # if we've set up our globals for preflight of app
  748.     begin
  749.         if (global gLaunchReqs)            # If we've defined any launch req's
  750.         begin
  751.             preFlightVal := PreFlight(gLaunchReqs);
  752.             if not (preFlightVal[1])                # If any of our launch req's are not satisfied
  753.             begin                                    # Fatal error
  754.                 PreflightString := preFlightVal[2];
  755.                 TCSEnd({ 3, global kTCSetLaunch },-1,"Failed the launch requirements for '{AppName}' - {PreflightString}",,,,-1); 
  756.             end;
  757.             else
  758.                 global gLaunchReqs := {};        # We passed the preflight now reset the launchreqs so we don't call preflight everytime thereafter.
  759.         end;
  760.     end;
  761.     tempAppName := "'"+ AppName + "'";                    # This is handle a problem that special characters can cause within
  762.                                                         # regular expressions
  763.     if not(match[application t:/≈{tempAppName}≈/])        # if desired app is not the current app
  764.     begin
  765.         if (global gLaunchTwitchHook2)        # Hook prior to launching
  766.             Call (gLaunchTwitchHook2);
  767.  
  768.         tempTypeSpeed := typespeed(50);                    # assign current typespeed to temp, then set to 50
  769.         global gPrevAppTitle :=  global gAppTitle;                    # Set previous app to the current app
  770.         if (global gPatchLaunchTwitch)                     # if we want to patch Launchtwitch
  771.             call(gPatchLaunchTwitch, AppName, AliasDir,LaunchApp);
  772.         else    # Were going to attempt to launch or twitch to the app
  773.         begin
  774.             if(global gIsSys7)
  775.             begin
  776.                 launchedByProcessList :=Twitcher(AppName);
  777.                 if(launchedByProcessList)
  778.                     returnVal := launchedByProcessList;                    
  779.                 else
  780.                 begin
  781.                     # Is it in the Apple Menu ?
  782.                     AppleMenuMatch := match[menuItem t:/≈{tempAppName}≈/ o:?menuord m:[menu t:""]]!;
  783.                     if (AppleMenuMatch) 
  784.                         returnval:= LaunchByAppleMenu(AppleMenuMatch.t);
  785.                     
  786.                     if (global gLaunchTwitchHook3)        # Hook prior to launching by type selecting
  787.                         Call (gLaunchTwitchHook3);
  788.                         
  789.                     if ( returnval = 0) and (LaunchApp)# if not in apple menu or alias not found
  790.                         returnval:= LaunchByTypeSelect(AppName, AliasDir);
  791.                 end;
  792.             end;    
  793.             else # Must be a 6.0.x System so we will launch with minilauncher
  794.                 returnVal := Minilaunch(AppName);    # System 6 branch
  795.         end;
  796.             
  797.         if TypeOf(returnval) = 'string' # Twitcher returns a string
  798.             returnval:= 1;
  799.             
  800.         if returnval > 0     # we're OK so far - keep checking
  801.         begin
  802.             ## Check to insure application actually launched
  803.             # 6.0 support Da's are not applications
  804.             if ( match[application t:/≈{tempAppName}≈/]) or (Match[window o:1 t:"{AppName}"]) 
  805.                 returnVal := MatchApplication(0);
  806.             else     # Desired application is not running
  807.                 returnVal := 0;
  808.         end;
  809.         else
  810.         begin
  811.             if (returnVal = -3)        # LaunchByAppleMenu returned not enough memory
  812.                 FailStr := "Not enough memory to launch";
  813.             else
  814.                 returnVal := 0;    # BG quit cancelled, twitchquit failed, or out of memory
  815.         end;
  816.     end;
  817.     else    # Desired App must be running
  818.         returnVal := MatchApplication();
  819.  
  820.     if (returnval)    # if we're up and running
  821.     begin
  822.         if (global gFillMemory)    # if global to fill up memory set on
  823.         begin
  824.             if not (DialogCheck(,,,[window o:1 s:dialog]!))    # make sure we're not modal - bail out if opening dialog present
  825.             begin
  826.                 LaunchFillMemApp();                        # launch the gFillMemApp
  827.                 Twitcher(returnval);                    # twitch back
  828.             end; # if not DialogCheck(,,,[window o:1 s:dialog]!)
  829.             else # there was an opening dialog present
  830.                 logstr("Opening dialog present.  Can't launch gFillMemApp");
  831.         end;
  832.     end;
  833.     else        # we failed our launch of gFillMemApp
  834.         logstr("'{AppName}' couldn't be launched successfully");
  835.  
  836.     # Reset the global values to their original values if necessary
  837.     gAppVerify := tempAppVerify;                    # assign back the original value
  838.     if not (typeof(tempTypeSpeed) = 'undefined')    # if typespeed has been reassigned
  839.         typespeed(tempTypeSpeed);                    # assign back the original value
  840.  
  841.     ### Set TCS ReturnValues
  842.     if (returnval)    # We were successful
  843.     begin
  844.         if(returnval = -3)    # Not enough memory expected fail
  845.         begin
  846.             if (SuiteBailOut)
  847.                 BailFlag := -1;
  848.             else
  849.                 BailFlag := '';
  850.             TCSEnd({ 3, global kTCSetLaunch }, -1, FailStr,,,,BailFlag);        # Launch failed/ Bail the suite
  851.             returnVal := 0;        # no memory means launch actually failed
  852.         end;
  853.         else
  854.             TCSEnd({ 3, global kTCSetLaunch },1,,,"Launch or twitch to '{AppName}'");
  855.     end;
  856.     else            # Otherwise
  857.         TCSEnd({ 3, global kTCSetLaunch },0);    # we were unsuccessfull - return a 0
  858.  
  859.     if (global gLaunchTwitchHook4)        # Hook prior returning 
  860.         Call (gLaunchTwitchHook4);
  861.         
  862.     return(returnVal);
  863. end; # LaunchTwitch();
  864.  
  865. #########################################################################
  866. #             PreFlight(List) - Called by LaunchTwitch, Set global 
  867. #                               gLaunchReqs to parameter list.
  868. #========================================================================
  869. # Author:        GS
  870. #
  871. # Description:    This routine will test whether or not your script will run on the 
  872. #                targets hardware and software configuration.  PreFlight will test 
  873. #                the machine for each selectors specified and return a fail if any 
  874. #                of the selectors fail.
  875. #
  876. # Parameters:    'fpu'        Returns a fail on machines that do not have an fpu.
  877. #                'color'     Returns a fail on machines that are not set to color.
  878. #                '8bd'        Returns a fail on machines that are not set to at least 8bit depth.
  879. #                'no68K'     Returns a fail on 68000 machines.
  880. #                'noCache'   Returns a fail on '040's that have caching turned on.
  881. #                'no32'        Returns a fail on cpu's with 32 bit addressing turned on
  882. #                '68k'        Returns a fail on cpu's that are not 68k based
  883. #                'PowerPC'    Returns a fail on cpu's that are not PowerPC based
  884. #
  885. # Returns:        fail: {0, 'Error Message'}
  886. #                pass:  {1, ''}
  887. #
  888. # Examples:        gLaunchReqs = {'fpu', 'color', '8bd', 'no68K', 'noCache'};
  889. #
  890. #========================================================================
  891. # History:
  892. # KTA    12/1/93    Added support for 'PowerPC' and '68k' in gLaunchReqs
  893. # KTA    12/1/93    fixed a bug in 'no32'
  894. # KTA    12/13/93 Preflight now returns a List with an error indicator and error message
  895. #########################################################################
  896. TASK PreFlight(myList)
  897. begin
  898.     returnVal := 0;
  899.     ErrorString := '';
  900.     
  901.     for each item in myList
  902.     begin
  903.     
  904.         #Test for fpu, drop out if not available
  905.         if (item = 'fpu') 
  906.         begin
  907.             if(GestaltFPUType() = "NoFPU")
  908.                 ErrorString := "This app requires an fpu and there is no fpu";
  909.         end;    
  910.         
  911.         #Test for PowerPC, drop out if not available
  912.         if (item = 'PowerPC') 
  913.         begin
  914.             if not(IsPowerPC())
  915.                 ErrorString := "PowerPC machine required and this target is 68k based";
  916.         end;    
  917.         
  918.         #Test for 68k, drop out if not available
  919.         if (item = '68k') 
  920.         begin
  921.             if (IsPowerPC())
  922.                 ErrorString := "68k based machine required and this target is PowerPC based";
  923.         end;    
  924.         
  925.         
  926.         #Test for color     
  927.         if (item = 'color') 
  928.         begin
  929.             match [screen m:true c:?isColor]!;
  930.             if not (isColor)
  931.                 ErrorString := "Color required and the menu monitor is not set to color";
  932.         end;    
  933.     
  934.     
  935.         #Test for at least 8 bit color
  936.         if (item = '8bd') 
  937.         begin
  938.             match [screen m:true p:?PixelDepth]!;
  939.             if not (PixelDepth >= 8)
  940.                 ErrorString := "At least 8 bit video required";
  941.         end;    
  942.     
  943.     
  944.         #Test for 68000
  945.         if (item = 'no68K') 
  946.         begin
  947.             if(GestaltProcessorType() = "68000")
  948.                 ErrorString := "CPU with a processor greater than 68000 required";
  949.         end;    
  950.         
  951.         
  952.         #Test for Cache
  953.         if (item = 'noCache') 
  954.         begin
  955.             if(OnTargetInit())
  956.             begin
  957.                 if(OnTarget("CacheTest")[2] = 1)
  958.                     ErrorString := "Requires that 040 Caching turned - OFF";
  959.             end;
  960.         end;
  961.         
  962.         if (item = 'no32')
  963.         begin    
  964.             if(Check32Bit()[1] = 1)
  965.                 ErrorString := "Requires that 32 bit addressing turned - OFF";
  966.         end;
  967.     end;
  968.     
  969.     if not (errorString)            # IF there was no errorString Preflight passed
  970.         returnVal := 1;
  971.     
  972.     return({returnVal,ErrorString});    # nothing failed
  973. end;
  974.  
  975.